import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Login from '../views/login.vue'
import Cookies from "js-cookie";

Vue.use(VueRouter)




const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/home',
    name: 'home',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: HomeView,

    redirect: to => {
      const userInfo = JSON.parse(Cookies.get("userInfo")); // 获取用户的mark值，假设使用了js-cookie库
      if (userInfo.mark === '1') {
        return '/aboutView'; // 如果mark为1，重定向到"/aboutView"页面
      } else if (userInfo.mark === '2') {
        return '/newAbout'; // 如果mark为2，重定向到"/newAbout"页面
      } else {
        return '/'; // 其他情况重定向到根路径"/"
      }
    },

    children: [
      { path: '/aboutView', component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'), },

      { path: '/newAbout', component: () => import(/* webpackChunkName: "about" */ '../views/newAbout.vue'), },
     


      { path: '/patent', component: () => import(/* webpackChunkName: "about" */ '../views/patent.vue'), },


      { path: '/markModel', component: () => import(/* webpackChunkName: "about" */ '../views/markModel.vue'), },
      { path: '/subjective', component: () => import(/* webpackChunkName: "about" */ '../views/subjective.vue'), },
      { path: '/synthesis', component: () => import(/* webpackChunkName: "about" */ '../views/synthesis.vue'), },


      { path: '/annualFee', component: () => import(/* webpackChunkName: "about" */ '../views/annualFee.vue'), },
      { path: '/recycle', component: () => import(/* webpackChunkName: "about" */ '../views/recycle.vue'), },
      { path: '/warn', component: () => import(/* webpackChunkName: "about" */ '../views/warn.vue'), },


      { path: '/sample', component: () => import(/* webpackChunkName: "about" */ '../views/sample.vue'), },


      { path: '/outpatient', component: () => import(/* webpackChunkName: "about" */ '../views/outpatient.vue'), },



      { path: '/recommend', component: () => import(/* webpackChunkName: "about" */ '../views/recommend.vue'), },
    ]
  }
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// const routerPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(to) {
//   return routerpush.call(this, to).catch(error=> error)
// } 

export default router
